package com.micro.commonlibrary.manage;

import android.app.Activity;

import java.util.Stack;
//
public class ActivityManage {

    private static Stack<Activity> mActivities = new Stack<>();

    private ActivityManage() {

    }

    public static void addActivity(Activity activity) {
        if (activity != null) {
            mActivities.add(activity);
        }
    }

    public static void removeActivity(Activity activity) {
        if (activity != null)
            mActivities.remove(activity);
    }

    public static Activity currentActivity() {
        return mActivities.lastElement();
    }

    public static boolean isExist(Activity activity) {
        return mActivities.contains(activity);
    }

    public static boolean isExist(String activityName) {
        for (Activity mActivity : mActivities) {
            if (mActivity.getClass().getName().equals(activityName)) {
                return true;
            }
        }
        return false;
    }

    //退出activity
    public static void allRemoveActivity() {
        for (Activity mActivity : mActivities) {
            mActivity.finish();
        }
    }


}
